package 设计模式.state;

import java.util.Random;

/**
 * ????齱????
 * @author Administrator
 *
 */
public class CanRaffleState extends State {

    RaffleActivity activity;

    public CanRaffleState(RaffleActivity activity) {
        this.activity = activity;
    }

    //???????????????????
    @Override
    public void deductMoney() {
        System.out.println("?????????????");
    }

    //????齱, ?????????????????????????
    @Override
    public boolean raffle() {
        System.out.println("????齱????????");
        Random r = new Random();
        int num = r.nextInt(10);
        // 10%?н?????
        if(num == 0){
            // ????????????? context
            activity.setState(activity.getDispenseState());
            return true;
        }else{
            System.out.println("???????г??н????");
            // ??????????齱
            activity.setState(activity.getNoRafflleState());
            return false;
        }
    }

    // ?????????
    @Override
    public void dispensePrize() {
        System.out.println("??н????????????");
    }
}
